package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Optional;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    // 根据手机号和密码查询用户（用于后续登录验证）
    @Select("SELECT * FROM user WHERE phone = #{phone} AND password = #{password}")
    User findByPhoneAndPassword(@Param("phone") String phone, @Param("password") String password);

    // 根据手机号查询用户信息
    @Select("SELECT * FROM user WHERE phone = #{phone}")
    List<User> findByPhone(@Param("phone") String phone);

    // 查询用户列表
    @Select("select * from user")
    List<User> findUserList();


    // 根据id查询用户的昵称和头像
    @Select("SELECT nickname, avatar FROM user WHERE user_id = #{userId}")
    User selectUserProfileById(Long userId);




    // 判断用户名是否已存在
    @Select("SELECT COUNT(*) FROM user WHERE username = #{username}")
    int checkUsernameExists(@Param("username") String username);
    @Select("select username from where phone = #{phone}")
    User selectOneByUserPhone(@Param("phone") String phone);
}
